#include <kernel.h>

struct dde_kit_lock
{
	 mutex_t lock;
};

void
LD_SYM(dde_kit_lock_init)(struct dde_kit_lock **out_lock)
{
	 struct dde_kit_lock *result;
	 *out_lock =
	 	  result = (struct dde_kit_lock *)
	 	  ekf_alloc(sizeof(struct dde_kit_lock));
	 mutex_init(&result->lock);
}

void
LD_SYM(dde_kit_lock_deinit)(struct dde_kit_lock *lock)
{
	 if (lock) ekf_free(lock);
}

void
LD_SYM(dde_kit_lock_lock)(struct dde_kit_lock *lock)
{
	 mutex_acquire(&lock->lock, NULL, NULL);
}

int
LD_SYM(dde_kit_lock_try_lock)(struct dde_kit_lock *lock)
{
	 int result = mutex_try_acquire(&lock->lock);
	 return result;
}

void
LD_SYM(dde_kit_lock_unlock)(struct dde_kit_lock *lock)
{
	 mutex_release(&lock->lock);
}

#if DK_EXPORT_SYM

void
dde_kit_lock_symbol(void)
{
	 elf_mod_export_symbol("dde_kit_lock_init", &dde_kit_lock_init, 1);
	 elf_mod_export_symbol("dde_kit_lock_deinit", &dde_kit_lock_deinit, 1);
	 elf_mod_export_symbol("dde_kit_lock_lock", &dde_kit_lock_lock, 1);
	 elf_mod_export_symbol("dde_kit_lock_try_lock", &dde_kit_lock_try_lock, 1);
	 elf_mod_export_symbol("dde_kit_lock_unlock", &dde_kit_lock_unlock, 1);
}

#endif
